import { defineStore } from 'pinia'
import { addressStore } from '@/stores'
import { ref } from 'vue'
import {
  orderDatas,
  transports,
  totalDatas,
  updateOrderData,
  updateTransportData,
  updateTotalData,
} from '@/data/timeData'
import {
  orderDataService,
  transportDataService,
  totalDataService,
} from '@/api/car'

export const timeDataStore = defineStore('timedata', () => {
  const orderData = ref([...orderDatas])
  const transportData = ref([...transports])
  const totalData = ref([...totalDatas])

  const address = addressStore()

  //获取订单池数据
  const fetchorderData = async () => {
    const res = await orderDataService({
      day_at: '2024-06-21',
      line_id: address.address1 + '_to_' + address.address2,
    })
    orderData.value = updateOrderData(res.result.info)
  }
  //获取当前运力数据
  const fetchtransportData = async () => {
    const res = await transportDataService({
      day_at: '2024-06-21',
      line_id: address.address1 + '_to_' + address.address2,
    })
    transportData.value = updateTransportData(res.result.info)
  }
  //获取实时总览数据
  const fetchtotalData = async () => {
    const res = await totalDataService({
      day_at: '2024-06-21',
      line_id: address.address1 + '_to_' + address.address2,
    })
    totalData.value = updateTotalData(res.result.info)
  }
  return {
    orderData,
    transportData,
    totalData,
    fetchorderData,
    fetchtransportData,
    fetchtotalData,
  }
})
